// 引用12306官网下载的站名目录，再格式化成自己想用的格式
const stations = require('./station_name_v10039')
const fs = require('fs');

function trans(key, value){
    let keyValue = {};
    keyValue[key] = value;
    return keyValue;
}
function format(){
    const stationArr = stations.data.split('@');
    const results = {};
    stationArr.forEach((item)=>{
        if (item) {
            const itemArr = item.split('|');
            const data = trans(itemArr[2], itemArr[1])
            Object.assign(results, data)
        }
    })
    console.log(results);
    fs.appendFile('./client/src/nodejs/stations.json', JSON.stringify(results), (err) => {
        if (err) {
            throw err;
        }
        console.log("JSON data is saved.");
    });
}

format();